package com.hznu.stmanage.serviceImpl;

import com.hznu.stmanage.dao.StudentMapper;
import com.hznu.stmanage.entity.Student;
import com.hznu.stmanage.service.BaseService;
import com.hznu.stmanage.service.StudentService;
import com.hznu.stmanage.utils.PasswordEncrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by J_Vino on 16/3/6.
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class StudentServiceImpl extends BaseService implements StudentService {

    @Autowired
    PasswordEncrypt passwordEncrypt;

    StudentMapper studentMapper = null;
    public void setMapper()
    {
        if(studentMapper==null)
            studentMapper = getStudentMapper();//1.获取相关mapper
    }
    public int deleteByPrimaryKey(Long id) {
        setMapper();
        return studentMapper.deleteByPrimaryKey(id);
    }

    //不使用
    public int insert(Student record) {
        setMapper();
        return studentMapper.insert(record);
    }

    public int insertSelective(Student record) {
        setMapper();
        passwordEncrypt.encryptStudent(record);
        return studentMapper.insertSelective(record);
    }

    public Student selectByPrimaryKey(Long id) {
        setMapper();
        return studentMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Student record) {
        setMapper();
        return studentMapper.updateByPrimaryKeySelective(record);
    }

    //不使用
    public int updateByPrimaryKey(Student record) {
        setMapper();
        return studentMapper.updateByPrimaryKey(record);
    }

    public Student findByID(String ID) {
        setMapper();
        return studentMapper.selectByID(ID);
    }
}
